package com.yyplatform.admin.platform.config.controller;

import static com.yyplatform.admin.Constants.URL_PREFIX;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yyplatform.admin.infra.model.RestResponse;
import com.yyplatform.admin.platform.config.model.dto.SysConfigSwiperDTO;
import com.yyplatform.admin.platform.config.model.dto.SysConfigSwiperFormDTO;
import com.yyplatform.admin.platform.config.model.dto.SysConfigSwiperQueryDTO;
import com.yyplatform.admin.platform.config.service.SysConfigSwiperService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * Created on 2024-11-25
 */
@Slf4j
@Tag(name = "配置/轮播图配置管理")
@AllArgsConstructor
@RestController
@RequestMapping(URL_PREFIX + "/sys/config/swiper/")
public class SysConfigSwiperController {


    private SysConfigSwiperService sysConfigSwiperService;

    @GetMapping("query")
    @Operation(summary = "查询")
    @RequiresPermissions("sys:swiperConfig:query")
    public RestResponse<Page<SysConfigSwiperDTO>> list(SysConfigSwiperQueryDTO queryDTO) {
        log.debug("query dto is {}", queryDTO);

        return RestResponse.ok(sysConfigSwiperService.listAll(queryDTO));
    }


    @GetMapping("get")
    @Operation(summary = "通过ID获取详情")
    @RequiresPermissions("sys:swiperConfig:get")
    public RestResponse<SysConfigSwiperDTO> get(Long id) {
        log.debug("get by id :{}", id);

        SysConfigSwiperDTO data = sysConfigSwiperService.get(id);
        return RestResponse.ok(data);
    }


    @PostMapping("save")
    @Operation(summary = "保存")
    @RequiresPermissions("sys:swiperConfig:save")
    public RestResponse<Void> save(@RequestBody SysConfigSwiperFormDTO sysConfigFormDTO) {
        log.debug("save dto is {}", sysConfigFormDTO);

        sysConfigSwiperService.save(sysConfigFormDTO);

        return RestResponse.ok(null);
    }


    @PostMapping("update")
    @Operation(summary = "修改")
    @RequiresPermissions("sys:swiperConfig:update")
    public RestResponse<Void> update(@RequestBody SysConfigSwiperFormDTO sysConfigFormDTO) {
        log.debug("update dto is {}", sysConfigFormDTO);

        sysConfigSwiperService.update(sysConfigFormDTO);
        return RestResponse.ok(null);
    }


    @PostMapping("delete")
    @Operation(summary = "删除")
    @RequiresPermissions("sys:swiperConfig:delete")
    public RestResponse<Void> delete(Long id) {
        log.debug("delete id is {}", id);

        sysConfigSwiperService.delete(id);
        return RestResponse.ok(null);
    }

}
